package com.ysy.tz.core.selfcomp;

import com.ysy.tz.core.engine.KeyValuePair;
import java.util.ArrayList;
import java.util.Iterator;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;

public class KeyValueTableColumn extends TableColumn {
    ObjectProperty<ArrayList<? extends KeyValuePair>> keyValuePairs = new SimpleObjectProperty();

    public KeyValueTableColumn() {
        this.keyValuePairs.addListener((observable, oldValue, newValue) -> {
            this.setCellFactory((column) -> {
                TableCell<Object, String> cell = new TableCell<Object, String>() {
                    protected void updateItem(String item, boolean empty) {
                        super.updateItem(item, empty);
                        if (empty) {
                            this.setText((String)null);
                        } else {
                            Iterator var3 = newValue.iterator();

                            while(var3.hasNext()) {
                                KeyValuePair keyValuePair = (KeyValuePair)var3.next();
                                if (keyValuePair.getKeyPair().equals(item)) {
                                    this.setText(keyValuePair.getValuePair());
                                    break;
                                }
                            }
                        }

                    }
                };
                return cell;
            });
        });
    }

    public ArrayList<? extends KeyValuePair> getKeyValuePairs() {
        return (ArrayList)this.keyValuePairs.get();
    }

    public ObjectProperty<ArrayList<? extends KeyValuePair>> keyValuePairsProperty() {
        return this.keyValuePairs;
    }

    public void setKeyValuePairs(ArrayList<? extends KeyValuePair> keyValuePairs) {
        this.keyValuePairs.set(keyValuePairs);
    }
}
